package cn.cost.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Restrictions;

import sun.font.CreatedFontTracker;

import cn.cost.dao.InsertDate;
import cn.cost.po.Classes;
import cn.cost.po.Faqs;

public class InsertDateImpl implements InsertDate {

	private SessionFactory sessionFactory;
	
	public int AddDate(Faqs faqs) {
		try {
			Serializable save = sessionFactory.getCurrentSession().save(faqs);
			System.out.println(save);
			System.out.println("=======================");
			return 1;
		} catch (Exception e) {
			return 0;
		}
	}

	public List<Faqs> selectAll() {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Faqs.class);
		//criteria.add(Restrictions.ilike("title",new String()));
		List<Faqs> list = criteria.list();
		for (Faqs item : list) {
			System.out.println(item.getTitle());
		}
		return list;
	}
	
	public List<Classes> selectClassesbyid(int id) {
		List<Classes> list = sessionFactory.getCurrentSession().createQuery("from Classes where id = "+id+"").list();
		return list;
	}
	
	public List<Classes> selectClasses() {
		List<Classes> list = sessionFactory.getCurrentSession().createQuery("from Classes").list();
		return list;
	}
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

}
